473,416 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

javascript populates dropdownlist

I have what may be a ViewState problem, but don't know how to deal with it:

I have 2 DropDownLists: ddlMed and ddlDosage. When the user selects a
medication from ddlMed, a javascript fires to populate ddlDosage with the
proper dosages for that medication. This works fine and the user is then
able to select a dosage and save the page.

The problem is that when the user hits the Save button, c# code processes
the form and saves the record and finds that the ddlDosage.SelectedValue is
empty, eventhough the user was able to see and select items from the
DropDownList.

I suspect the problem is related to the fact that the ddlDosage DropDownList
was populated on the client side and the server can't see it. Is that
correct? How can I make this work?
Thanks
/Ken

Feb 10 '07 #1
2 5439
On Feb 10, 11:58 pm, ken s <k...@discussions.microsoft.comwrote:
I have what may be a ViewState problem, but don't know how to deal with it:

I have 2 DropDownLists: ddlMed and ddlDosage. When the user selects a
medication from ddlMed, a javascript fires to populate ddlDosage with the
proper dosages for that medication. This works fine and the user is then
able to select a dosage and save the page.

The problem is that when the user hits the Save button, c# code processes
the form and saves the record and finds that the ddlDosage.SelectedValue is
empty, eventhough the user was able to see and select items from the
DropDownList.

I suspect the problem is related to the fact that the ddlDosage DropDownList
was populated on the client side and the server can't see it. Is that
correct? How can I make this work?
Thanks
/Ken
you can make a hidden field that capture your value for second list
and use it in your code

For example, make this in your form

<input id="__Dosage" type="hidden" name="__Dosage" runat="server">

When javascript populated ddlDosage, make the following

document.getElementById("__Dosage").value=...;

and make

Me.ddlDosage.Attributes.Add("onchange",
"document.getElementById('__Dosage').value=this.va lue;")

Finally your selected value in code-behind will be as

Me.__Dosage.Value

Feb 11 '07 #2
Alexey,
Thank you for the assistance -- with examples no less. It worked perfectly.
Spasiba

>
you can make a hidden field that capture your value for second list
and use it in your code

For example, make this in your form

<input id="__Dosage" type="hidden" name="__Dosage" runat="server">

When javascript populated ddlDosage, make the following

document.getElementById("__Dosage").value=...;

and make

Me.ddlDosage.Attributes.Add("onchange",
"document.getElementById('__Dosage').value=this.va lue;")

Finally your selected value in code-behind will be as

Me.__Dosage.Value


Feb 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Caesar Augustus | last post by:
I'm having a problem with two different javascript controls in my app. The first chuck of javascript that I pasted into my app is the client-side calendar control popup which works fine when first...
1
by: Rose | last post by:
Hi, I'm new to asp.net and c#, so this is probably an easy question for everybody. I want to have a dropdownlist (populated by states), when the user selects a different value, populate a...
1
by: craig | last post by:
Hi, I've been asked to create a page that dynamically populates the contents of related drop down lists using JavaScript, and then obviously posts things back to the server. For completeness,...
1
by: senthilnathan1985 | last post by:
sir, am implementing javascript in my project am begineer to javascript and asp.net can you please help me for the following queries here am using one dropdownlist which contains number of...
3
by: Radu | last post by:
Hi. I have the following problem - I need to build a user-control in asp.net (an ascx) to somehow allow the users to search by first name or last name among a big (~10.000 records) email addresses...
4
by: basm101 | last post by:
Hello, I need to know how to create closing tag elements when using DOM to add in form elements to a page. Here is the code...the <div> I am adding to the page is called dropDownList (for...
1
by: KRISHNA PRAVI | last post by:
the error is "runtime error object expected" here is the code....................................................................................... <script language="javascript"...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i'm in a gridview edit row that has a DropDownList in one column and a status Label in the 2nd column. When i changed the value in the dropdownlist, there's a client-side javascirpt...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.